import sys
input = sys.stdin.readline
def f(a, b, x, c):
n1, m1 = n, m
if c == 1:
x = 4 - x
if xx % 2:
n1, m1 = m, n
if x == 1:
a, b = b, n1-a+1
elif x == 2:
a, b = n1 - a + 1, m1 - b + 1
elif x == 3:
a, b = m1-b+1, a
return (a, b)
n, m, xx, y, z, p = map(int, input().split())
xx %= 4
y %= 2
z %= 4
for _ in range(p):
a, b = map(int, input().split())
a, b = f(a, b, xx, 0)
if y == 1:
if xx % 2:
b = n-b+1
else:
b = m-b+1
a, b = f(a, b, z, 1)
print(a, b)
#define aavade(a,n) for(ll i=0;i<n;i++) cin>>a[i]
#define f(i,x,n) for(int i=x;i<n;i++)
#define bf(i,n,x) for(int i=n-1;i>=x;i--)
#define ll long long int
#define Max 1000000000+7
#define ull unsigned long long int
#include<bits/stdc++.h>
using namespace std;
bool prime[1000000];
void SieveOfEratosthenes(ll n)
{
memset(prime, true, sizeof(prime));
for (ll p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (ll i = p * p; i <= n; i += p)
prime[i] = false;
}
}
}
vector<int> Divisors(int n)
{
vector<int> v;
for (int i=1; i<=sqrt(n); i++)
{
if (n%i == 0)
{
// If divisors are equal, print only one
if (n/i == i)
v.push_back(i);
else // Otherwise print both
{
v.push_back(i);
v.push_back(n/i);
}
}
}
return v;
}
bool isPrime(int n)
{
// Corner case
if (n <= 1)
return false;
// Check from 2 to square root of n
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
int vis[1000001];
vector<int> g[1000010];
vector<vector<int>> conn;
vector<int> curr_c;
vector<int> vere[1000000];
int cnt=0,cc[1000000];
void dfs_graph(int vertex)
{
vis[vertex]=1;
curr_c.push_back(vertex);
cc[vertex]=cnt;
vere[cnt].push_back(vertex);
for(int child:g[vertex])
{
if(vis[child]) continue;
dfs_graph(child);
}
}
ll height[500001];
ll depth[500001];
int c[100001];
vector<int> ans;
void dfs_tree(ll vertex,ll par=0)
{
// cout<<"-->"<<vertex<<'\n';
int k=c[vertex];
for(ll child:g[vertex])
{
if(child==par) continue;
depth[child]=depth[vertex]+1;
// cout<<c[child]<<" "<<c[vertex]<<"\n";
k*=c[child];
dfs_tree(child,vertex);
height[vertex]=max(height[vertex],height[child]+1);
}
if(k==1) ans.push_back(vertex);
}
string getbinary(int x)
{
string s;
bf(i,10,0)
{
s+=to_string((x>>i)&1);
}
return s;
}
void subsetsUtil(vector<int>& A, vector<vector<int> >& res, vector<int>& subset, int index)
{
res.push_back(subset);
for (int i = index; i < A.size(); i++) {
subset.push_back(A[i]);
subsetsUtil(A, res, subset, i + 1);
subset.pop_back();
}
return;
}
vector<vector<int> > subsets(vector<int>& A)
{
vector<int> subset;
vector<vector<int> > res;
int index = 0;
subsetsUtil(A, res, subset, index);
return res;
}
int visa[300010];
ll n,r1,c1,r2,c2;
int matrix[1000][1000];
int matrix1[1000][1000];
vector<pair<int,int>> vp;
// ll cnt=0;
map<pair<ll,ll>,ll> mp;
// void dfs_matrix(ll i,ll j)
// {
// if(i<0 or j<0) return;
// if(i>=n or j>=n) return;
// if(matrix[i][j]=='1') return;
// // cout<<i<<" "<<j<<'\n';
// matrix[i][j]='1';
// vp[cnt].push_back({i,j});
// mp[{i,j}]=cnt;
// dfs_matrix(i-1,j);
// dfs_matrix(i+1,j);
// dfs_matrix(i,j-1);
// dfs_matrix(i,j+1);
// }
ll power(ll x, ll y,ll p)
{
ll res = 1;
while (y > 0) {
if (y % 2 == 1)
res = ((res%p) * (x%p))%p;
y = y >> 1;
x = ((x%p * x%p))%p;
}
return res % p;
}
bool check(ll x,ll a[],ll k,ll n)
{
ll moves=0;
for (int i=n/2; i<n; i++)
{
if (x-a[i]>0) moves+=x-a[i];
if (moves>k) return false;
}
if (moves<=k) return true;
else return false;
}
void solve()
{
ll n,m,x,y,z,p,nn,mm;
cin>>n>>m>>x>>y>>z>>p;
pair<ll,ll> v[p];
for(int i =0;i<p;++i)
{
cin>>v[i].first>>v[i].second;
nn = n; mm = m;
f(j,0,x%4){
swap(v[i].first,v[i].second);
v[i].second = nn-v[i].second+1;
swap(nn,mm);}
f(j,0,y%2)
v[i].second = mm-v[i].second+1;
f(j,0,z%4)
{
swap(v[i].first,v[i].second);
v[i].first=mm-v[i].first+1;
swap(nn,mm);
}
cout<<v[i].first<<" "<<v[i].second<<'\n';}
}
int main()
{
int t = 1;
while(t--)
{
solve();
}
}
577A - Multiplication Table | 817C - Really Big Numbers |
1355A - Sequence with Digits | 977B - Two-gram |
993A - Two Squares | 1659D - Reverse Sort Sum |
1659A - Red Versus Blue | 1659B - Bit Flipping |
1480B - The Great Hero | 1519B - The Cake Is a Lie |
1659C - Line Empire | 515A - Drazil and Date |
1084B - Kvass and the Fair Nut | 1101A - Minimum Integer |
985D - Sand Fortress | 1279A - New Year Garland |
1279B - Verse For Santa | 202A - LLPS |
978A - Remove Duplicates | 1304A - Two Rabbits |
225A - Dice Tower | 1660D - Maximum Product Strikes Back |
1513A - Array and Peaks | 1251B - Binary Palindromes |
768B - Code For 1 | 363B - Fence |
991B - Getting an A | 246A - Buggy Sorting |
884A - Book Reading | 1180A - Alex and a Rhombus |